import { useRouter } from "vue-router";
import { YkMessage } from "@yike-design/ui";
export function useCode() {
  const router = useRouter();

  //code验证
  const tackleCode = (code: number) => {
    //请求成功
    if (code === 200) {
      return true;
    }
    //token过期或token验证失败，跳转到登录页面，重新登录获取token
    else if (code === 300) {
      router.push("/login");
      YkMessage({
        type: "warning",
        message: "token过期或token验证失败,请重新登录",
      });
      return false;
    }
    //参数错误
    else if (code === 400) {
      YkMessage({ type: "warning", message: "参数错误" });
      return false;
    }
    //未注册
    // else if(code === 401){
    //     YkMessage({type:'warning', message: '未注册，请先注册'})
    //     router.push('/register')
    //     return false;
    // }
    else {
      YkMessage({ type: "warning", message: "未知错误" });
      return false;
    }
  };

  return {
    tackleCode,
  };
}
